#!/usr/bin/env python
#-*- coding:utf-8 -*-

import os
import sys
import string
import pymongo
import ConfigParser

#read config
cf = ConfigParser.ConfigParser()
cf.read(os.path.dirname(os.path.realpath(__file__))+"/settings.conf")
dbClientUser = cf.get("MongoDB", "dbClientUser")
dbWapUser = cf.get("MongoDB", "dbWapUser")
host = cf.get("MongoDB", "host")
port = cf.getint("MongoDB", "port")
maxPoolSize = cf.getint("MongoDB", "maxPoolSize")
networkTimeout = cf.getint("MongoDB", "networkTimeout")


def connMongoDB(db):
    connection = pymongo.Connection(host, port, maxPoolSize, networkTimeout)
    db = connection[db]
    connection.disconnect()
    return db

def connMongoDB_2():
    connection = pymongo.Connection(host, port, maxPoolSize, networkTimeout)
    return connection

def connMongoDB_ClientUser():
    return connMongoDB(dbClientUser)

def connMongoDB_WapUser():
    return connMongoDB(dbWapUser)

def main():
    db = connMongoDB_ClientUser()
    print db.find()

if __name__ == '__main__':
    main()